package com.dmzc.priorityqueue;

import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * 11.找出一个流式数据第k大的元素
 */
public class PriorityQueue1 {
    private final static int MAX_SIZE = 3;

    public static void main(String[] args) {
        PriorityQueue priorityQueue = new PriorityQueue();
        Scanner scanner = new Scanner(System.in);
        int next = 0;
        while (true) {
            next = scanner.nextInt();
            if (priorityQueue.size() < MAX_SIZE) {
                priorityQueue.add(next);
            } else {
                if ((int) priorityQueue.peek() < next) {
                    System.out.println("淘汰" + priorityQueue.poll());
                    priorityQueue.add(next);
                }
            }
            if (priorityQueue.size() >= 3) {
                System.out.println(priorityQueue);
                System.out.println("此次第3大：" + priorityQueue.peek());
            }
        }
    }
}
